/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.inria.openmath.omapi.implementation;

/**
 *
 * @author Mr.Sam
 */
import fr.inria.openmath.omapi.*;

/**
 * The <code>NodeListImpl</code> class provides an ordered collection of nodes.
 * <p>The items in the <code>NodeList</code> are accessible via an integral
 * index, starting from 0.
 */

public class NodeListImpl implements NodeList {

    private Node parent;

    public NodeListImpl (Node parent) {
        this.parent = parent;
    }



    /**
     * @see fr.inria.openmath.omapi.NodeList#item
     */
    public Node item(int index) {
        // OPTIM cache access        
        Node n;
        int i = index;
        n = parent.getFirstChild();
        while (n != null && (i > 0)) {
            i--;
            n = n.getNextSibling();
        }
        return n;
    }



    /**
     * @see fr.inria.openmath.omapi.NodeList#getLength
     */
    public int getLength() {
        Node n;
        int l = 0;

        n = parent.getFirstChild();
        while (n != null) {
            l++;
            n = n.getNextSibling();
        }
        return l;
    }

}
